// Core Test Support
// Copyright 2004 (C) Ralph Thomas

// This was stolen from RalphTV

#ifndef TEST_CORE_H
#define TEST_CORE_H

namespace test {
	//
	/// This interface is derived from to implement every test.
	/// Instances of tests get registered with the 
	/// test::runnerSingleton, which then invokes the performTest
	/// method on every registered instance. Once it has done that
	/// it deletes them all.
	///
	class basic {
	  public:
		virtual ~basic();

		//
		// bool performTest()
		//
		/// Execute the test that this test class implements.
		///
		/// \return	NULL if the test was successful, a string naming the failure otherwise.
		//
		virtual const char* performTest();

		//
		// const char* getTestName()
		//
		/// Return the name of the this test. This name is
		/// used to identify the test if it fails, so it
		/// should probably refer to the file the test is
		/// contained in.
		///
		/// \return	name of test
		//
		virtual const char* getTestName();
	};


	//
	/// The runnerSingleton runs all of the tests which are
	/// registered with it. A test program has to implement
	/// the registerTests method of the runnerSingleton, e.g.:
	///
	/// void runnerSingleton::registerTests() {
	///	adoptTest( new myTestOne );
	///	adoptTest( new myTestTwo );
	///	...
	/// }
	//
	class runnerSingleton {
	  public:
		//
		// void registerTests()
		//
		/// This member function must be implemented by
		/// the test program. It should call adoptTest
		/// on each test instance it wants executed.
		///
		/// \sa adoptTest
		//
		void registerTests();

		//
		// void adoptTest( basic* t )
		//
		/// Adopt the specified test. This means that all
		/// memory associated with the test will be owned
		/// by the runnerSingleton.
		///
		/// \param	t	the test instance to adopt
		//
		virtual void adoptTest( basic* t ) = 0;
	};
};

#endif

